#!/bin/bash
# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

HOME=/remote/iosg/home-2/donggu
source $HOME/.zshrc
cd $HOME;source ~/miniconda3/etc/profile.d/conda.sh;conda activate coin2_env
cd workspace/coin

# Pull

git fetch && git reset --hard origin/master
git submodule update --init

pushd ../coin_deploy
git fetch && git reset --hard origin/master
popd

pushd ../coin_binary
git fetch && git reset --hard origin/master
popd

pushd ../lm_export
git fetch && git reset --hard origin/master
popd


set -x

# Build sim. We don't use coin_binary's sim
bazel build --config opt //cc/appcoin2/strategy/lm:sim   

GROUP=$1
EXP=v$(date +"%m%d")-$GROUP
python cc/appcoin2/experimental/donggu/research/gen_research.py $EXP $GROUP 1 | sd '&$' '' | parallel --jobs 0
python cc/appcoin2/experimental/donggu/research/report/report.py $EXP
python cc/appcoin2/experimental/donggu/research/report/make_pr.py \
    $EXP \
    "$(git --git-dir ../coin/.git log --pretty="prestolabs/coin@%h  %ai (%>(15)%cr)  %>(15)%an: %s" -1)" \
    "$(git --git-dir ../coin_binary/.git log --pretty="prestolabs/coin_binary@%h  %ai (%>(15)%cr)  %>(15)%an: %s" -1)" \
    "$(git --git-dir ../coin_deploy/.git log --pretty="prestolabs/coin_deploy@%h  %ai (%>(15)%cr)  %>(15)%an: %s" -1)" \
    "$(git --git-dir ../lm_export/.git log --pretty="prestolabs/lm_export@%h  %ai (%>(15)%cr)  %>(15)%an: %s" -1)"
